package com.situ.util;

import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Map;

public class BeanFactory {
    private static Map<Class<?>,Object> beanMap = new HashMap<>();
    public static <T> T getBean(Class<T> clazz){

        T t=(T) beanMap.get(clazz);
        if(t!=null){
            return t;
        }
        try {
            Constructor<T> constructor = clazz.getDeclaredConstructor();
             t = constructor.newInstance();
             beanMap.put(clazz,t);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return t;
    }
}
